//
//  LXMessageViewController.m
//  bgms_d
//
//  Created by lachesis-zhu on 03/07/2017.
//  Copyright © 2017 lachesis-zhu. All rights reserved.
//

#import "LXMessageViewController.h"
#import "BoomDetailViewController.h"
#import "BoomDoubleDetailVC.h"

@interface LXMessageViewController ()
@property (nonatomic, assign) BOOL hasIn;
@end

@implementation LXMessageViewController

#pragma mark -  public method

#pragma mark -  life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.showWarnLabel.numberOfLines = 3;
    self.showWarnLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    self.showWarnLabel2.numberOfLines = 3;
    self.showWarnLabel2.lineBreakMode = NSLineBreakByTruncatingTail;
    
    self.switchBtn.onTintColor = kAppSwitchOnCloor;
    self.switchBtn.tintColor = kAppSwitchOnCloor;
    self.switchBtn.transform = CGAffineTransformMakeScale( 1.5, 1.5);
    
    [self.boomArrays enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = obj;
        UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDown:)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        [view addGestureRecognizer:tap];
        
        UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
        longPressGesture.minimumPressDuration = 1.0f;//设置长按 时间
        [view addGestureRecognizer:longPressGesture];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.hasIn = NO;
}

- (void)viewDidAppear:(BOOL)animated
{
    
}

#pragma mark -  notification
- (void)tapDown:(UITapGestureRecognizer *)tap
{
    [self.boomArrays enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = obj;
        view.backgroundColor =kAppThemeColor;
    }];
    UIView *view = tap.view;
    view.backgroundColor = kAppGrayBgColor;
    
    LXBoomSelectType type = view.tag + 1000 + 1;
    if (view.tag < 2) {
        BoomDoubleDetailVC *vc = [[BoomDoubleDetailVC alloc] initWithNibName:NSStringFromClass([BoomDoubleDetailVC class]) bundle:nil];
        vc.boomType = type;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        BoomDetailViewController *vc = [[BoomDetailViewController alloc] initWithNibName:NSStringFromClass([BoomDetailViewController class]) bundle:nil];
        vc.boomType = type;
        [self.navigationController pushViewController:vc animated:YES];
    }
    [self boomStyle:type close:NO];
}

- (void)longPress:(UILongPressGestureRecognizer *)gesture
{
    [self.boomArrays enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = obj;
        view.backgroundColor =kAppThemeColor;
    }];
    [self boomStyle:boomCloseType close:YES];
    [self boomStyle:beatStrobeType close:YES];
    self.switchBtn.on = NO;
}

- (void)boomStyle:(LXBoomSelectType)type close:(BOOL)colse
{
    UInt8 data[3];
    data[0] = 0x78;
    data[1] = colse ? 0x00 : 0x01;
    data[2] = (type - 1000) & 0xff;
    [[BLETransDeviceSingleton sharedInstance] characteristc:LED_CHARACTERISTIC_UUID sendHostCmd:data lenght:3];
}

- (IBAction)strobeDown:(UISwitch *)sender
{
    if (sender.isOn) {
        [self boomStyle:beatStrobeType close:NO];
    } else {
        [self boomStyle:beatStrobeType close:YES];
    }
}

- (void)dealloc
{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
